<template>
  <div class="wrapper">
    <div>
      <div class="text">接收者:</div>
      <cube-input type="text" v-model="received_id" placeholder="接收者ID" />
    </div>
    <div>
      <div class="text">金额:</div>
      <cube-input type="text" v-model="amount" placeholder="转让金额" />
    </div>
    <cube-button primary @click="save">提交</cube-button>
  </div>
</template>

<script>
import api from '@/api'
import base64 from '@/util/base64'
export default {
  name: 'T',
  data() {
    return {
      received_id: '',
      amount: 0,
      disabled: false
    }
  },
  methods: {
    save() {
      if (!this.received_id || isNaN(this.received_id) || +this.received_id < 0) {
        return this.$createToast({
          type: 'error',
          txt: '接收者错误',
          time: 1000
        }).show()
      }
      if (isNaN(this.amount) || +this.amount <= 0.01) {
        return this.$createToast({
          type: 'error',
          txt: '金额错误',
          time: 1000
        }).show()
      }
      if (!this.disabled) {
        this.disabled = true
        api.Exec.transfer({
          received_id: this.received_id,
          amount: this.amount
        }).then(() => {
          this.$createToast({
            type: 'correct',
            txt: '操作成功',
            time: 1000
          }).show()
          setTimeout(() => {
            this.$router.push('/account/balance?type=2')
          }, 800)
        }).finally(() => {
          this.disabled = false
        })
      }
    }
  },
  created () {
  },
  activated () {
  },
  deactivated () {
  }
}
</script>

<style scoped lang="stylus">
.wrapper
  background white
  padding 20px
  height 300px
  display flex
  flex-direction column
  justify-content space-around
  .text
    height 30px
    line-height 30px
    text-align left
    font-size 14px
    font-weight 700
</style>
